/*
 * @Version: 0.0.1
 * @Author: ider
 * @Date: 2020-07-20 21:50:26
 * @LastEditors: ider
 * @LastEditTime: 2020-07-21 00:27:44
 * @Description:
 */

package main

import (
	"log"
	"math/rand"
	"sort"
)

type AwardCheck struct {
	redbool  []int
	bluebool int
}

func NewAwardCheck(redbool []int, bluebool int) *AwardCheck {
	return &AwardCheck{
		redbool:  redbool,
		bluebool: bluebool,
	}
}

func (c *AwardCheck) CheckAward(redbool []int, bluebool int) int {
	rc := 0
	bc := 0
	for i := 0; i < 6; i++ {
		if c.redbool[i] == redbool[i] {
			rc += 1
		}
	}
	if c.bluebool == bluebool {
		bc += 1
	}

	if rc == 6 && bc == 1 {
		return 1
	} else if rc == 6 {
		return 2
	} else if rc == 5 && bc == 0 {
		return 3
	} else if (rc == 5 && bc == 0) || (rc == 4 && bc == 1) {
		return 4
	} else if (rc == 4 && bc == 0) || (rc == 3 && bc == 1) {
		return 5
	} else if bc == 1 {
		return 6
	}
	return 7
}

type RandomWorksr struct {
	generator *rand.Rand
}

func NewRandomWorksr(seed int64) *RandomWorksr {
	return &RandomWorksr{
		generator: rand.New(rand.NewSource(seed)),
	}
}

func (c *RandomWorksr) GetTicket() ([]int, int) {
	set := make(map[int]bool)
	var redbool []int

	for {
		if len(redbool) == 6 {
			break
		}

		ret := int(c.generator.Intn(31))

		if _, ok := set[ret]; ok {
			continue
		}
		redbool = append(redbool, ret)
		set[ret] = true
	}
	sort.Ints(redbool)
	bluebool := int(c.generator.Intn(16))
	return redbool, bluebool
}

func work(seed int64) {
	// rw := NewRandomWorksr(time.Now().UnixNano())
	rw := NewRandomWorksr(seed)

	ac := NewAwardCheck([]int{9, 15, 18, 21, 23, 26}, 8)
	// startT := time.Now()
	for i := 0; i < 1000000; i++ {
		redbool, bluebool := rw.GetTicket()
		if ret := ac.CheckAward(redbool, bluebool); ret < 2 {
			log.Println(seed, i, ret, redbool, bluebool)
		}
	}
	// tc := time.Since(startT) //计算耗时
	// fmt.Printf("time cost = %v\n", tc)
}

func main() {
	for i := 0; i < 10000000; i++ {
		work(int64(i))
	}
}
